#include "FFmpegDemo.h"
#include <iostream>
#include <chrono>
#include <thread>

void FFmpegDemo::processFrame(const FrameData &frame)
{
    // 将AVFrame转换为OpenCV Mat
    cv::Mat img(frame.frame->height, frame.frame->width, CV_8UC3);
    uint8_t *dst_data[1] = {img.data};
    int dst_linesize[1] = {img.step[0]};

    // 设置像素格式范围
    int range = frame.frame->format == AV_PIX_FMT_YUVJ420P ? 1 : 0;
    sws_setColorspaceDetails(sws_ctx_,
                             sws_getCoefficients(SWS_CS_DEFAULT), range,
                             sws_getCoefficients(SWS_CS_DEFAULT), range,
                             0, 1 << 16, 1 << 16);

    sws_scale(sws_ctx_,
              frame.frame->data, frame.frame->linesize,
              0, frame.frame->height,
              dst_data, dst_linesize);

    // 显示帧
    cv::imshow("Video Frame", img);
    cv::waitKey(1);
}
